package org.gc.baseframe.util;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;

import org.apache.log4j.Logger;

/**
 * <p>Title: </p>
 * <p>Description: Print Debug Info</p>
 * <p>Copyright: Copyright (c) 2009</p>
 * <p>Company: </p>
 * <p>LastModified: </p>
 * @author wangdong
 * @version 1.0
 */
public class DebugPrinter {

    private static Logger logger = Logger.getRootLogger(); //Log4j logger

    /**
     * Print String
     * @param str String
     */
    public static void printString(String str) {
        logger.debug("#### Print String Start ####");
        logger.debug(str);
        logger.debug("#### Print String End ####");
    }

    /**
     * Print Exception
     * @param e Exception
     */
    public static void printException(Exception e) {
        logger.debug("#### Print Exception Start ####");
        logger.debug(e);
        logger.debug("#### Print Exception End ####");
    }

    /**
     * Print 2 dim Vector
     * @param data Vector
     */
    public static void print2DimVector(Vector data) {
        logger.debug("#### Print 2 Dim Vector Start ####");
        StringBuffer temp = new StringBuffer("\n");
        for(int i = 0; i < data.size(); ++i) {
            Vector row = (Vector)data.elementAt(i);
            for(int j = 0; j < row.size(); ++j) {
                Object obj =  row.elementAt(j);
                temp.append(obj).append("  ");
            }
            temp.append('\n');
        }
        temp.substring(0, temp.length() - 1);
        logger.debug(temp.toString());
        logger.debug("#### Print 2 Dim Vector End ####");
    }

    /**
     * Print 1 dim Vector
     * @param data Vector
     */
    public static void print1DimVector(Vector data) {
        logger.debug("#### Print 1 Dim Vector Start ####");
        StringBuffer temp = new StringBuffer("\n");
        for(int i = 0; i < data.size(); ++i) {
            Object obj = data.elementAt(i);
            temp.append(obj).append("  ");
        }
        logger.debug(temp.toString());
        logger.debug("#### Print 1 Dim Vector End ####");
    }

    /**
     * Print 2 dim List
     * @param data List
     */
    public static void print2DimList(List data) {
        logger.debug("#### Print 2 Dim List Start ####");
        StringBuffer temp = new StringBuffer("\n");
        for(int i = 0; i < data.size(); i++) {
            List row = (List)data.get(i);
            for(int j = 0; j < row.size(); j++) {
                temp.append(row.get(j)).append("  ");
            }
            temp.append('\n');
        }
        temp.substring(0, temp.length() - 1);
        logger.debug(temp.toString());
        logger.debug("#### Print 2 Dim List End ####");
    }

    /**
     * Print 1 dim List
     * @param data List
     */
    public static void print1DimList(List data) {
        logger.debug("#### Print 1 Dim List Start ####");
        StringBuffer temp = new StringBuffer("\n");
        for(int i = 0; i < data.size(); i++) {
            temp.append(data.get(i)).append("  ");
        }
        logger.debug(temp.toString());
        logger.debug("#### Print 1 Dim List End ####");
    }

    /**
     * print 2 dimension String Array
     * @param data String[][]
     */
    public static void print2DimStringArray(String[][] data) {
       logger.debug("#### Print 2 Dim String Array Start ####");
       StringBuffer temp = new StringBuffer("\n");
       for (int rowIdx = 0; rowIdx < data.length; rowIdx++) {
           for (int colIdx = 0; colIdx < data[rowIdx].length; colIdx++) {
               temp.append(data[rowIdx][colIdx]).append("  ");
           }
           temp.append('\n');
       }
       logger.debug(temp.toString());
       logger.debug("#### Print 2 Dim String Array End ####");
    }
    
    /**
     * print Map
     * @param map Map
     */
    public static void printMap(Map map) {
    	logger.debug("#### Print Map Start ####");
    	StringBuffer temp = new StringBuffer();
    	Set set = map.keySet();
    	Iterator iter = set.iterator();
    	while(iter.hasNext()) {
    		String key = (String)iter.next();
    		Object value = map.get(key);
    		temp.append("key=" + key + ";value=" + value + "\n");
    	}
    	logger.debug(temp.toString());
    	logger.debug("#### Print Map End ####");
    }
}
